{include file="public/header"/}
<link rel="stylesheet" href="/public/static/admin/easyui/layui-v2.6.8/css/layui.css">
<link rel="stylesheet" type="text/css" href="/public/static/admin/easyui/jeasyui/themes/icon.css">

<style>
	body {
		overflow-y: hidden;
	}

	.matchCon {
		width: 280px;
	}

	#tree {
		background-color: #fff;
		width: 239px;
		border: solid #ddd 1px;
		margin-left: 5px;
		height: 100%;
		flex: none;
	}

	h3 {
		background: #EEEEEE;
		border: 1px solid #ddd;
		padding: 5px 10px;
	}

	.wrapper .grid-wrap {
		position: relative;
		flex: 1;
	}

	.grid-wrap h3 {
		border-bottom: none;
	}

	#tree h3 {
		border-style: none;
		border-bottom: solid 1px #D8D8D8;
	}

	.quickSearchField {
		padding: 10px;
		background-color: #f5f5f5;
		border-bottom: solid 1px #D8D8D8;
	}

	#searchCategory input {
		width: 165px;
	}

	.innerTree {
		overflow-y: auto;
	}

	#hideTree {
		cursor: pointer;
		color: #fff;
		padding: 0 4px;
		background-color: #B9B9B9;
		border-radius: 3px;
		position: absolute;
		top: 5px;
		right: 5px;
	}

	#hideTree:hover {
		background-color: #AAAAAA;
	}

	#clear {
		display: none;
	}

	.chk-list {
		line-height: 28px;
	}

	.url-box {
		padding: 5px 15px;
		line-height: 26px;
		cursor: pointer;
	}

	.url-box a {
		margin-right: 5px;
	}

	td.img {
		background: url("/css/img/no_pic.gif") center no-repeat
	}

	.number_sku {
		padding: 13px 13px 0 0;
		position: absolute;
		right: 10px;
		top: 12px;
	}

	.number_sku:hover {
		cursor: pointer;
	}

	td[aria-describedby=grid_name] {
		position: relative;
	}

	.add {
		background: #fff url("/css/img/number_sku.png") no-repeat
	}

	.plus {
		background: #fff url("/css/img/number_sku.png") no-repeat 0 -13px
	}

	.ui-btn-menu .menu-btn b {
		border-color: white transparent transparent;
	}

	.ui-btn-menu-cur #btn-add {
		color: #555 !important;
		font: 14px/2 \5b8b\4f53;
	}

	.ui-btn-menu-cur b {
		border-color: #888 #fafafa #fafafa !important;
	}

	#grid_currentQty {
		text-align: left;
	}

	.btn_query_inventory {
		background: url(/css/img/btn_query_inventory.png) center center no-repeat;
		height: 100%;
		width: 100%;
		display: block;
	}

	.ui-state-hover .btn_query_inventory {
		background-image: url(/css/img/btn_query_inventory_hover.png);
	}

	td[aria-describedby=grid_inventory] {
		border-right-color: #FFF !important;
	}

	#grid_inventory {
		border-right-color: #EEE
	}

	.ztree.showRoot li ul.level0 {
		background: url(./img/line_conn.gif) 0 0 repeat-y;
		padding: 0 0 0 18px;
	}

	.ztree.showRoot li span.button.switch.level0 {
		visibility: visible;
		width: 18px;
	}

	.layui-input,
	.layui-select,
	.layui-textarea {
		height: 30px;
		line-height: 30px;
	}

	.layui-form-select dl dd.layui-this {
		background-color: #ddd;
		color: #000;
	}

	.ui-input {
		height: auto;
	}

	.ui-btn-bill {
		height: auto;
	}

	.layui-form-checkbox[lay-skin=primary] i {
		padding: 0;
	}

	.layui-form-checkbox[lay-skin=primary]:hover i {
		border-color: #5dc5e7;
	}

	.layui-form-checked[lay-skin=primary] i {
		border-color: #5dc5e7;
		background-color: #5dc5e7;
	}

	.ui-btn-hl:hover {
		color: #5f5f5f;
	}
</style>

<div class="bill-ser-top">
	<ul class="ul-inline cf layui-form">
		<li>
			<input type="text" id="matchCon" class="ui-input matchCon ui-input-ph" placeholder="按商品编号，商品名称，商品条码，规格型号等查询"
				style="font-size: 12px;">
		</li>
		<li id="li_check" class="chk-list" style="display: list-item;">
			<!-- <label>审核状态:</label> -->
			<span id="goods_state_type">
				<span class="ui-combo-wrap ui-combo-active" style="width: 118px;">
					<input type="text" class="input-txt" autocomplete="off" readonly="readonly"
						style="cursor: default; width: 92px;" value="全部" id="state_type_name">
					<span class="trigger"></span>
				</span>
			</span>
		</li>
		<li class="chk-list" id="chk-isZero" style="display: list-item;">
			<input type="checkbox" value="1" name="is_default" lay-skin="primary" id="isZero" title="显示零库存商品">
		</li>
		<li class="chk-list" id="chk-isNearPrice" style="display: list-item;">
			<input type="checkbox" value="1" name="is_default" lay-skin="primary" id="isNearPrice" title="显示最近价">
		</li>
		<li><a class="ui-btn ui-btn-search" id="search">查询</a></li>
		<li><a class="ui-btn" id="btn-refresh">刷新</a></li>
		<li class="url-box" id="openUrl">
			<!-- <a href="https://club.kingdee.com/club/newclub/school/course?product_id=7&amp;cid=1547#pid=5693" target="_blank" class="video-icon"></a>商品管理 -->
		</li>
	</ul>

	<!-- 审核状态 -->
	<div class="ui-droplist-wrap" id="goods_state_type_wrap"
		style="position: absolute; z-index: 1000; width: 118px; display: none;">
		<div class="droplist" style="position: relative; overflow: auto; min-height: 150px; height: 150px;">
			<div class="list-item selected" data-value="2" title="全部">全部</div>
			<div class="list-item" data-value="0" title="显示启用商品">显示启用商品</div>
			<div class="list-item" data-value="1" title="显示禁用商品">显示禁用商品</div>
		</div>
	</div>

</div>

<div class="wrapper btc">
	<div class="ui-config-box">
		<span id="config" class="ui-config">
			<a href="#" class="ui-icon-config-new"></a>
			列设置
		</span>
	</div>

	<div class="bill-ser-botm cf">
		<div class="fr ml10">
			<div class="ui-btn-menu ml10" style="margin-right: 0px;">
				<!-- <a class="ui-btn-bill ui-btn-hl menu-btn mrb ui-btn-add" style="width: 40px;padding-right: 14px;"
					href="/admin/goods/add.html" id="btn-add">新增
					<b></b>
				</a> -->

				<!-- <a class="ui-btn-bill ui-btn-hl menu-btn mrb ui-btn-add ta" tabid="purchase" data-right="PU_ADD" tabTxt="新增商品" parentOpen="true" rel="pageTab" _href="/admin/goods/add.html"><span></span>新增</a> -->

				<a class="ui-btn-bill ui-btn-hl menu-btn mrb ui-btn-add"
					onclick="goodsEdit('/admin/goods/add.html','purchase','新增商品')"><span></span>新增</a>

				<div class="con hl more-operate-con" style="margin-left: 0px;font-size: 14px;width: 58px;padding: 4px;">
					<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
						<li><a href="#" id="btn-add-category">新增类别</a></li>
					</ul>
				</div>
			</div>
			<a href="#" class="ui-btn-bill ui-btn-hl ml10" id="btn-batchSet">批量设置</a>
			<a href="#" class="ui-btn-bill ui-btn-hl ml10" id="btn-disable" onclick="disable(1)">禁用</a>
			<a href="#" class="ui-btn-bill ui-btn-hl ml10" id="btn-enable"  onclick="disable(0)">启用</a>
			<a href="#" class="ui-btn-bill ui-btn-hl ml10" id="btn-import">导入</a>
			<a href="#" class="ui-btn-bill ui-btn-hl ml10" id="btn-export">导出</a>
			<a href="#" class="ui-btn-bill ui-btn-hl ml10" id="btn-batchDel" onclick="delss()">删除</a>
		</div>
	</div>

	<div class="cf" style="display: flex;">
		<div class="grid-wrap fl cf">
			<h3>当前分类：<span id='currentCategory'></span><a href="javascript:void(0);" id='hideTree'>&gt;&gt;</a></h3>
			<table id="grid">
			</table>
			<div id="page"></div>
		</div>

		<div class="fl cf" id="tree">
			<h3>快速查询</h3>
			<div class="quickSearchField dn">
				<form class="ui-search" id="searchCategory">
					<input type="text" class="ui-input"><button type="submit" title="点击搜索">搜索</button>
				</form>
			</div>

			<ul class="easyui-tree" id="tt">
				<!-- <li>
					<span>全部</span>
					<ul>
						<li>
							<span>包装物</span>
							<ul>
								<li>
									<span>酒盒</span>
									<ul>
										<li>
											<span>三尺坊贰拾</span>
										</li>
									</ul>
								</li>
								<li>
									<span>瓶子</span>
									<ul>
										<li>
											<span>500ml 茅头小子瓶</span>
										</li>
									</ul>
								</li>
								<li>
									<span>酱香</span>
								</li>
								<li>
									<span>其他</span>
								</li>
								<li>
									<span>清香</span>
								</li>
							</ul>
						</li>
					</ul>
				</li> -->
			</ul>

		</div>
	</div>
</div>

<div style="display: none;">
	<input type="hidden" id="state_type_id" />
</div>

<!-- 列表鼠标移入显示大图的容器 -->
<div id="maxImg" style="position: absolute;z-index: 999;display: none;">
	<img src="/public/static/admin/css/img/btn_descease_normal.png" width="250" height="250" />
</div>



<script src="/public/static/admin/easyui/layui-v2.6.8/layui.js"></script>
<script type="text/javascript" src="/public/static/admin/easyui/jeasyui/jquery.easyui.min.js"></script>

<script type="text/javascript">
	//查询
	$("#search").click(function () {
		var matchCon = $("#matchCon").val();
		var state_type_name = $("#state_type_name").val();
		var isZero = $("#isZero").val();
		var isNearPrice = $("#isNearPrice").val();

		$("#grid").jqGrid('setGridParam', {
	        datatype: 'json',
	        postData: { 
		        'ajax': '100',
		        'matchCon':matchCon,
		        'state_type_name':state_type_name,
		        'isZero':isZero,
		        'isNearPrice':isNearPrice,
		        'search':1 
	        }, //发送数据 
	        page: 1
      	}).trigger("reloadGrid"); //重新载入

			//删除查询缓存
		   	var postData = $("#grid").jqGrid("getGridParam", "postData"); 
	　　　　	$.each(postData, function (k, v) { 
	　　　　　　delete postData[k];  
	　　　　	}); 

	})
	//批量删除
	function delss(){
		var ids=$("#grid").jqGrid('getGridParam','selarrrow');
		$.ajax({
			type: 'POST',
			url: "delss.html",
			data: { ids: ids , dels : '1',},
			dataType: "json",
			async: false,
			error: function (request) {
				layer.msg("发送请求失败！");
			},
			success: function (data) {
				if (data.status == 1) {
					layer.msg(data.msg);
					$("#grid").jqGrid('setGridParam').trigger("reloadGrid"); //重新载入
				} else {
					layer.msg(data.msg);
				}

			}
		});

	}
	//批量 禁用 和 启用 0是禁用 1是启用
	function disable(id){

		var ids=$("#grid").jqGrid('getGridParam','selarrrow');
		$.ajax({
			type: 'POST',
			url: "disable.html",
			data: { id: id, ids: ids },
			dataType: "json",
			async: false,
			error: function (request) {
				layer.msg("发送请求失败！");
			},
			success: function (data) {
				if (data.code == 1) {
					layer.msg(data.msg);
					$("#grid").jqGrid('setGridParam').trigger("reloadGrid"); //重新载入
				} else {
					layer.msg(data.msg);
				}

			}
		});

	}

	// 页面跳转（修改）
	function goodsEdit(_href, tabid, tabTxt) {
		parent.tab.addTabItem({
			tabid: tabid,
			text: tabTxt,
			url: _href
		})
	}
	// 监听列表图片（鼠标移入事件）
	function mouseover(x, img, id) {
		console.log(id)
		var tableImg = "tableImg" + id;
		var top = $("#" + tableImg).offset().top;
		var left = $("#" + tableImg).offset().left;
		$("#maxImg>img").attr("src", img)
		$("#maxImg").show();
		$("#maxImg").css({ "top": (top + 24) + "px", "left": (left + 24) + "px" });

	};
	// 监听列表图片（鼠标移出事件）
	function mouseout(params) {
		$("#maxImg").hide();
	}


	$(document).ready(function () {

		// 列表大图鼠标移入移出
		$("#maxImg").hover(function () {
			$("#maxImg").show();
		}, function () {
			$("#maxImg").hide();
		});

		// 跳转打开新标签页
		$(".ta").click(function () {
			var tabid = $(this).attr('tabid');
			var tabTxt = $(this).attr('tabTxt');
			var _href = $(this).attr('_href');
			parent.tab.addTabItem({
				tabid: tabid,
				text: tabTxt,
				url: _href
			})
		})

		var l = 270;
		$("#hideTree").click(function (e) {
			e = $(this);
			"&gt;&gt;" === e.html() ? (e.html("&lt;&lt;"), l = 0, $("#tree").hide()) : (e.html("&gt;&gt;"), l = 270, $("#tree").show()), Public.resizeGrid(100, l);
		});

		$(window).resize(function () {
			Public.resizeGrid(95, l), $(".innerTree").height($("#tree").height() - 95)
		}),
			Public.setAutoHeight($("#tree")), $(".innerTree").height($("#tree").height() - 95);

		$("#grid").jqGrid({
			url: '/admin/goods/index.html?ajax=100',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			//width: Public.setGrid().w,
			//height: Public.setGrid().h,
			colNames: ["", "操作", "图片", "商品编号", "商品名称", "商品条码", "商品标签", "辅助属性", "商品类别", "规格型号", "单位", "首选仓库", "当前库存", "期初数量", "单位成本", "期初总价", "预计采购价", "零售价", "批发价", "VIP会员价", "备注", "状态", "是否常用"],
			colModel: [
				{ name: 'id', index: 'id', width: 60, hidden: true },
				{ name: 'id', index: 'id', width: 100, formatter: cLink },
				{ name: 'img', width: 50, formatter: imgs, align: 'center' },
				{ name: 'sn', width: 100 },
				{ name: 'name', width: 200 },
				{ name: 'code', width: 120 },
				{ name: 'title', width: 60 },
				{ name: 'attribute', width: 60 },
				{ name: 'category_name', width: 100 },
				{ name: 'model', width: 100 },
				{ name: 'unit', width: 40 },
				{ name: 'store_name', width: 80 },
				{ name: 'stock_num', width: 100 },
				{ name: 'begin_num', width: 80 },
				{ name: 'cost_price', width: 100 },
				{ name: 'begin_total_price', width: 100 },
				{ name: 'estimated_purchase_price', width: 100 },
				{ name: 'sale_price', width: 100 },
				{ name: 'batch_price', width: 100 },
				{ name: 'vip_price', width: 100 },
				{ name: 'mark', width: 100 },
				{ name: 'status', formatter: cStatus, width: 80, align: "center" },
				{ name: 'is_common', formatter: cCommon, width: 80, align: "center" },
			],
			rowNum: 10,
			rowList: [10, 20, 30],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置
			multiselect: true,//自带多选
			// multiboxonly:true,//变成单选
			pgbuttons: true,//翻页按钮
			pagination: true,
			altRows: !0,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			checkOnSelect: true,
			cmTemplate: {
				sortable: !1,
				title: !1
			},
			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			}
		});

		function imgs(cellvalue, options, rowObject) {
			var img = '/public/static/admin/icon/no_pic.gif';
			if (rowObject.img_path != null) {
				img = '/public/uploads/' + rowObject.img_path;
				return '<img src="' + img + '" id="tableImg' + rowObject.id + '" width="40px" height="40px" onmouseout="mouseout()" onmouseover="mouseover(this, \''  + img + '\',' + rowObject.id + ')"/>';
			}
			else{
				return '<img src="' + img + '" id="tableImg' + rowObject.id + '" width="40px" height="30px" />';
			}
		}
		
		function cLink(cellvalue, options, rowObject) {
			return '<div class="operating"><span class="ui-icon ui-icon-pencil" onclick="goodsEdit(\'/admin/goods/edit.html?id=' + rowObject.id + '\',\'purchase\',\'修改商品\')" title="修改"></span><span class="ui-icon ui-icon-copy" onclick="goodsEdit(\'/admin/goods/copy.html?id=' + rowObject.id + '\',\'purchase\',\'复制商品\')" title="复制"></span><span class="ui-icon ui-icon-trash" onclick="del(' + rowObject.id + ')" title="删除"></span></div>'
		}

		function cStatus(cellvalue, options, rowObject) {
			if (rowObject.status == 0) {
				return '<span class="set-status open" data-delete="false" onclick="switchs(this,' + rowObject.id + ')"><span class="ui-icon-circle"></span></span>';
			} else {
				return '<span class="set-status close" data-delete="false" onclick="switchs(this,' + rowObject.id + ')"><span class="ui-icon-circle"></span></span>';
			}
		}

		function cCommon(cellvalue, options, rowObject) {
			console.log(rowObject.status);
			if (rowObject.is_common == 0) {
				return '<span class="common-set-status common-set-default" onclick="common(this,' + rowObject.id + ')" data-delete="false" ></span>';
			} else {
				return '<span class="common-set-status common-set-success" onclick="common(this,' + rowObject.id + ')" data-delete="true" ></span>';
			}
		}
	});

	function switchs(obj, id) {
		if ($(obj).hasClass("open")) {
			$(obj).removeClass("open");
			$(obj).addClass("close");
			status = 1;
		} else {
			$(obj).removeClass("close");
			$(obj).addClass("open");
			status = 0;
		}

		$.ajax({
			type: 'POST',
			url: "save.html",
			data: { id: id, status: status },
			dataType: "json",
			async: false,
			error: function (request) {
				layer.msg("发送请求失败！");
			},
			success: function (data) {
				if (data.status == 1) {
					layer.msg(data.msg);
				} else {
					layer.msg(data.msg);
				}

			}
		});
	}

	function common(obj, id) {
		if ($(obj).hasClass("common-set-default")) {
			$(obj).removeClass("common-set-default");
			$(obj).addClass("common-set-success");
			is_common = 1;
		} else {
			$(obj).removeClass("common-set-success");
			$(obj).addClass("common-set-default");
			is_common = 0;
		}

		$.ajax({
			type: 'POST',
			url: "save.html",
			data: { id: id, is_common: is_common },
			dataType: "json",
			async: false,
			error: function (request) {
				layer.msg("发送请求失败！");
			},
			success: function (data) {
				if (data.status == 1) {
					layer.msg(data.msg);
				} else {
					layer.msg(data.msg);
				}

			}
		});
	}

</script>

<script>
	$('#tt').tree({
		url: 'getGoodCategory.html',
		onClick: function (node) {
			f5('index.html?ajax=100&goods_category=' + node.id);
			// alert('index.html?goods_category=' + node.id);  // alert node text property when clicked
		}
	});

	$(document).ready(function () {
		// 选择审核状态
		$("#goods_state_type").click(function () {
			var top = $(this).offset().top;
			var left = $(this).offset().left;
			$("#goods_state_type_wrap").css({ "top": (top + 25) + "px", "left": (left) + "px" });
			$("#goods_state_type_wrap").toggle();
		});
		// 类别赋值
		$("#goods_state_type_wrap .list-item").click(function () {
			var title = $(this).attr("title");
			var val = $(this).attr("data-value");
			$("#state_type_name").val(title);
			$("#state_type_id").val(val);
			$(this).addClass("selected").siblings().removeClass("selected");
			$("#goods_state_type_wrap").hide();

			// 通过id判断收入、支出。显示对应的搜索框
			if (val == 1) {
				$("#othertype2").css({ "display": "list-item" });
				$("#othertype3").css({ "display": "none" });
			} else if (val == 2) {
				$("#othertype2").css({ "display": "none" });
				$("#othertype3").css({ "display": "list-item" });
			}
		});
	});

	//选择类别-选择框外点击则隐藏
	$(document).mouseup(function (e) {
		if (e.target.id != "state_type_name") {
			var con = $("#goods_state_type_wrap");   // 设置目标区域
			if (!con.is(e.target) && con.has(e.target).length === 0) {
				$("#goods_state_type_wrap").hide();
			}
		}
	});
</script>


{include file="public/footer"/}